package pl.com.kyhu.dietex3000.GUI.dialogs;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

public class AboutDialog extends Dialog {

	protected Object result;
	protected Shell shell;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public AboutDialog(Shell parent, int style) {
		super(parent, style);
		setText("About program");
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER);
		shell.setSize(450, 300);
		shell.setText(getText());
		
		Label titleLabel = new Label(shell, SWT.NONE);
		titleLabel.setFont(SWTResourceManager.getFont("Microsoft Sans Serif", 31, SWT.NORMAL));
		titleLabel.setBounds(82, 24, 279, 51);
		titleLabel.setText("O programie");
		
		Label aboutLabel = new Label(shell, SWT.WRAP);
		aboutLabel.setBounds(57, 92, 324, 80);
		aboutLabel.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus massa ipsum, interdum non porttitor et, dictum sit amet urna. Nullam pretium aliquam diam, at consequat velit aliquet id. Praesent rutrum id tortor vitae molestie. Integer pulvinar, leo ut blandit lacinia.");
		
		Button okButton = new Button(shell, SWT.NONE);
		okButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				shell.close();
			}
		});
	
		okButton.setBounds(168, 191, 100, 33);
		okButton.setText("OK");

	}
}
